# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.contrib import admin

from .models import Link, SideBar
from blogApp.custom_site import custom_site
from blogApp.base_admin import BaseOwnerAdmin


@admin.register(Link, site=custom_site)
class LinkAdmin(BaseOwnerAdmin):
    # 配置列表页面展示的字段
    list_display = ('title', 'href', 'status', 'weight', 'created_time')
    # 后台管理显示的字段
    fields = ('title', 'href', 'status', 'weight')
    # 获得登录信息
    def save_model(self, request, obj, form, change):
        obj.owner = request.user
        return super(LinkAdmin, self).save_model(request, obj, form, change)


@admin.register(SideBar, site=custom_site)
class SideBarAdmin(BaseOwnerAdmin):
    # 配置列表页面展示的字段
    list_display = ('title', 'display_type', 'content', 'created_time')
    # 后台管理显示的字段
    fields = ('title', 'display_type', 'content')

    # 获得登录信息
    def save_model(self, request, obj, form, change):
        obj.owner = request.user
        return super(SideBarAdmin, self).save_model(request, obj, form, change)
